package top.lyc829.mymusic.adapter

import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.youth.banner.adapter.BannerAdapter
import com.youth.banner.util.BannerUtils
import top.lyc829.mymusic.R
import top.lyc829.mymusic.adapter.BannerAdapter.ImageHolder
import top.lyc829.mymusic.databinding.ItemBannerBinding
import top.lyc829.mymusic.ext.load
import top.lyc829.mymusic.model.bean.Banner

/**
 * 自定义布局，网络图片
 */
class BannerAdapter(mDatas: List<Banner?>?) : BannerAdapter<Banner?, ImageHolder>(mDatas) {
    override fun onCreateHolder(parent: ViewGroup, viewType: Int): ImageHolder {
        val imageView = BannerUtils.getView(parent, R.layout.item_banner) as ImageView
        return ImageHolder(imageView)
    }

    override fun onBindView(holder: ImageHolder, data: Banner?, position: Int, size: Int) {
        if (data != null) {
            val binding : ItemBannerBinding = ItemBannerBinding.bind(holder.itemView)
            binding.bannerImage.load(data.pic, 20)
        }
    }

    class ImageHolder(view: View) : RecyclerView.ViewHolder(view) {
        var imageView: ImageView
        init {
            imageView = view as ImageView
        }
    }
}